Skip to content

feat(hip): Inkling 2's attention at each layer's bias extent, tiny-inkling2-mini's 128 and 256 beside Mini's 1,024 - #5499

Merged
ashhart merged 7 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-attn-extent
Dec 1, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-attn-extent

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

HIP1's attention (#4633) fixes the relative-bias extent at 1,024, so it cannot serve hf-internal-testing/tiny-inkling2-mini, whose local layers have an extent of 128 (the window) and whose global layers have 256. This makes HIP1 follow each layer's extent, as asked on #4265 (issuecomment-7215811144), and adds tiny-mini's heads, window and extents to the HIP attention contract. Mini's kernels and outputs are unchanged.

  • The shared FP64 reference core/contract/inkling2_attn_ref.zig takes the extent per call: Call.extent, 1,024 by default. CUDA's callers and cases are unchanged, and there is no separate HIP reference.
  • Only the bias-table kernel depends on the extent. tf_ink2_rel_table stays Mini's 1,024 kernel, with the same symbol and machine code; tf_ink2_rel_table_e256 and tf_ink2_rel_table_e128 are new compile-time instances. Each writes rows of 1,024 distances with zeros past its extent, so the four attention kernels read one layout at every extent and do not change.
  • relTable() launches the extent's kernel and refuses any other extent with error.UnsupportedRelExtent, before a launch. layerExtent(text, i, why) reads a layer's extent from the parsed config and names the refusal: "layer {i}'s relative-bias extent {e} has no HIP bias table: tf_ink2_rel_table is built at extents 1024, 256 and 128".
  • The HIP attention contract adds tiny-mini's cases at 4 query and 2 KV heads:
    • prep on sliding and global layers with three streams, and both new tables;
    • sliding rows at window 128, with edges at 127 to 129 keys and across a 256-key chunk;
    • fold, split and prompt rows past extent 256, with edges at 255 to 257 keys and across 1,024-key sub-chunks and 16,384-key chunks;
    • three streams against each alone, split and prompt bit-equal to the fold, and the exact-P rows.
  • Gate 4 on tiny-mini's sliding layer: over 128 keys, fp16 sums in the 32-lane order came out exact, so in that window the second 32 of every 64 keys are 32 times larger. Mini's values are unchanged, and a host test fails without that change.
  • The extent tests read fixtures/tiny_mini_config.json from test(inkling2): tiny-inkling2-mini config and model header fixtures with parse, weight map and visit plan tests #5369.

Why compile-time extents: templating the four attention kernels would add 8 kernels to cover, and a run-time extent would change Mini's machine code. Writing zeros past the extent keeps one table layout for all three.

Checks on this head

  • Head commit: 20d8275, on main 51fee3c.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 93 and 93, 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test-inkling2-hip-host -Dhip=true: 76 of 78 passed, 2 skipped.
    • On a clean tree of this head: zig build test-inkling2-cuda-host 62 of 62; zig build test-inkling2-host 61 of 66, 5 skipped; zig build test-kernel-contract 365 of 365.
    • zig build test on the same tree: 14,489 of 14,588 passed, 98 skipped, 1 failed. The failure is stage_hip_test "every staged call on HIP memory equals the reference, whole and in parts", which fails on main on this machine as well.
    • zig build test -Dhip=true on the same tree: 1,604 of the 1,628 tests it ran passed, 23 skipped, and the same stage_hip_test failed.
    • The new tests fail before their change: on 6345c5b the reference test does not compile (no field extent) and the HIP host tests give 6 compile errors. A reference default of 1,000 instead of 1,024 turns 5 tests red, the new ones among them.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • Mini and CUDA unchanged, checked before the rebase (base 6345c5b against the same commits):
    • A code-object comparison on gfx1151: Mini's six attention kernels (tf_ink2_prep, tf_ink2_rel_table, tf_ink2_attn, tf_ink2_attn_fold, tf_ink2_attn_prompt, tf_ink2_merge) are identical and the two new tables are added. The tool also flags affine_dot2_block instantiations in tiles/dot2.hip, which this branch does not touch and in which two builds of the same tree differ.
    • Mini's 78 lines of the HIP contract are identical on base and head; the group's limits line counts 8 launches instead of 6.
    • A scratch harness hashed the reference's want and tol over CUDA's attention contract cases (57 path and shape combinations with their edges, 3 fills, 3 seeds) and the gate-4 replays: 612 identical lines on base and head. A second check over 48 random calls, 22 of them global rows past 1,024, gave identical hashes on base and head. The value pinned in the test "CUDA's default extent and an explicit 1,024 keep the base bits on global rows past 1,024, windows and rings" was computed on 6345c5b, before Call.extent existed.
    • The reference against a key-by-key FP64 attention written from the definition, at extents 128, 256 and 1,024 with positions around each extent: worst difference 1.1e-16, and simulate bit-equal. That check is now a test, with one-off-the-extent controls that go red.
  • CI: run 46135580076 on 20d8275: 9 checks pass, the 2 nightly jobs skip, and zig-windows fails at zig build -Dfixed-cpu compile-native-cuda-windows with "no module named 'flashnext_memory' available within module 'checkpoint_cli'" in zig/src/cli/tfq3_validate.zig. That failure is inherited: this branch touches no build or CLI file, and flashnext cuda: size the rows-store staging permit from the served window #5501 and flashnext tfq3: route B=2..16 decode windows in parallel and build the dedup lists in parallel, bit for bit #5506 fail the same step with the same error.
  • Not run, and why:
    • CUDA's and Metal's contracts on a device: there is no NVIDIA or Apple device here. CUDA's callers and files are unchanged.
    • gfx1030, gfx1100 and gfx1201 on a device: I have only gfx1151. The limits audit checks their records.
    • Resumed/fresh and pass-boundary checks on tiny-mini: no HIP engine calls these kernels yet.
    • Timing: Mini's machine code is unchanged, and the two new tables are not timed.

Receipt

n/a: no engine or server calls these kernels yet. The kernel contract below is the evidence.

Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract (tf-hip-kernel-contract image inkling2): tf_ink2_rel_table_e256 and tf_ink2_rel_table_e128, beside tf_ink2_rel_table (Mini's 1,024), which they do not replace. Each output is held to the shared FP64 reference at the call's extent, within the contract's bound for fp32 sums rounded to bf16; the tables have no bit-exact oracle.

  • A planted control for each new kernel, each its own kernel, red at shapes: each new table reading rel_logits_proj one column late, global rows given a bias past extent 256, and a window one key past 128.

  • Each backend's SUMMARY line and exit status (gfx1151, ROCm 10.1's hipcc, HIP 7.16):

    SUMMARY inkling2 HIP full: 27 kernels: 27 pass gates 1-4, 0 fail, 0 known findings; 12 controls: 12 red as planted, 0 missed; 0 limit problems; gates 209800 ms, limits 5 ms (exit 0), on a clean tree of this head. The base has 13 kernels and 8 controls.

    zig build hip-kernel-contract -Dhip-arch=gfx1151, before the rebase: SUMMARY gfx1151 224 kernels: 224 pass gates 1-4, 0 fail, 2 known findings; 78 controls: 78 red as planted, 0 missed; 2 limit problems; gates 869607 ms, limits 2971 ms (exit 1). The two limit problems are tf_moe_combine_gate and tf_vl_resize, whose records the base's limits audit also flags as stale.

    zig build hip-kernel-contract-limits: 11 problems on base and head, the same 11, none in the Inkling 2 groups. The two new records are current on all four chips.

  • Chips I could not run: gfx1030, gfx1100 and gfx1201 (limits only), and every CUDA SM and Metal chip.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (n/a: no engine)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a: no engine)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (n/a: Mini's bits are unchanged; the new tables use the same sums)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (n/a: no engine)

@ashhart

ashhart commented Nov 30, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Reviewed, with one device check asked: we ran the full Inkling 2 HIP kernel contract on a gfx1151 GPU at this head and at main. This head adds no failure over main beyond the planted controls going red, and the two new kernels' resource-limit records now match their compiled sizes.

  • Synthena

@ashhart
ashhart force-pushed the feat/hip-inkling2-attn-extent branch from 150b3c9 to 718a050 Compare November 30, 2026 22:27
@ashhart

ashhart commented Nov 30, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Checked at this head: the reviewed change re-placed on current main, keeping every main row in the conflicting files; this head's CI passed.

  • Synthena

AbrahamCete and others added 7 commits December 1, 2026 02:26
… per call

Call.extent is a layer's relative-bias extent: the window on local
layers, rel_extent on global ones. It defaults to 1,024, the extent the
reference had fixed, so CUDA's attention contracts compile unchanged and
keep their want and tol bits. The bias table rows are the call's extent
long, and global keys past it gather by ring slot with no bias.

A test checks a global row at extent 256 and a sliding row at window and
extent 128 (tiny-inkling2-mini's two layers): each on its own table
equals extent 1,024 on that table padded with zeros, to float64 rounding
(gate 4's replay bit for bit), and the bias past 256 moves the row.
… and 128 beside Mini's 1,024

tf_ink2_rel_table is one macro body built at three extents: Mini's 1,024
(the same symbol and code) and tiny-inkling2-mini's 256 (global layers)
and 128 (local) as tf_ink2_rel_table_e256 and tf_ink2_rel_table_e128.
Each reads rel_logits_proj as [16][extent] and writes a row of 1,024
distances, zeros past its extent, so the attention kernels read one
table layout at every extent and keep their code; tile.hpp's kExtent
is kTabRow, the row length.

relTable takes the layer's extent and launches its kernel, refusing any
other before a launch (UnsupportedRelExtent). layerExtent reads a
layer's extent from the parsed config (the window on local layers,
rel_extent on global ones) and refuses one with no kernel by name, with
config.Why naming the layer, its extent and the three built.

The contract registers both new tables at tiny-mini's 4 heads, each
with a control reading rel_logits_proj a column late, and their gate-5
records come from the code objects. Mini's registrations and records
are unchanged.
…ds, window and extents

The HIP attention contract's fills, prep and rows take a checkpoint's
geometry (fill.Model: query and key heads, window, rel_extent, n_floor).
Mini's registrations keep their names, shapes and inputs. Beside them,
tiny-inkling2-mini's run at 4/2 heads: prep (sliding, global and three
streams), sliding rows at window 128 with edges at 127 to 129 keys and
across a 256-key chunk, global fold, split and prompt rows past extent
256 with edges at 255 to 257 keys and across 1,024-key sub-chunks and
16,384-key chunks, three streams in one launch against each alone, the
split and prompt against the fold, and the exact-P rows. The reference
reads each call's table at its extent; the device gets it padded to
1,024 distances.

Gate 4's values cancel over a sliding layer's window, so a 128-key
window is its own period; there the second 32 of every 64 keys are 32
times larger, so 32-lane fp16 sums lose bits too, and a host test pins
fp32 exact with fp16 and bf16 missing. Two more controls go red: global
rows given bias past extent 256, and a window one key past 128.
…loat64, CUDA's default bits pinned, HIP extent refusals
@ashhart
ashhart force-pushed the feat/hip-inkling2-attn-extent branch from 718a050 to 130ab19 Compare December 1, 2026 02:26
@ashhart
ashhart merged commit 0fb0db1 into ashhart:main Dec 1, 2026
5 of 10 checks passed
@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thank you @AbrahamCete. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

AbrahamCete added a commit to AbrahamCete/TensorFold that referenced this pull request Dec 1, 2026
…tract launchers

Zig 0.17 requires each source file to belong to one module. After ashhart#5012,
ashhart#4994, ashhart#5499 and ashhart#5728, inkling2_hip, inkling2_loop_hip,
inkling2_experts_hip and the stream state targets all imported config.zig
directly, causing duplicate module ownership inside tf-hip-kernel-contract.

Group the shared Inkling 2 family files (config, plan, names, names_test,
loop, kept_state, hip_weights, config_test) into
zig/src/families/inkling2/hip_family.zig and pass one inkling2_family
module into the Inkling 2 HIP launcher and state modules.
ashhart pushed a commit to AbrahamCete/TensorFold that referenced this pull request Dec 1, 2026
…tract launchers

Zig 0.17 requires each source file to belong to one module. After ashhart#5012,
ashhart#4994, ashhart#5499 and ashhart#5728, inkling2_hip, inkling2_loop_hip,
inkling2_experts_hip and the stream state targets all imported config.zig
directly, causing duplicate module ownership inside tf-hip-kernel-contract.

Group the shared Inkling 2 family files (config, plan, names, names_test,
loop, kept_state, hip_weights, config_test) into
zig/src/families/inkling2/hip_family.zig and pass one inkling2_family
module into the Inkling 2 HIP launcher and state modules.
ashhart pushed a commit that referenced this pull request Dec 1, 2026
…tract launchers

Zig 0.17 requires each source file to belong to one module. After #5012,
#4994, #5499 and #5728, inkling2_hip, inkling2_loop_hip,
inkling2_experts_hip and the stream state targets all imported config.zig
directly, causing duplicate module ownership inside tf-hip-kernel-contract.

Group the shared Inkling 2 family files (config, plan, names, names_test,
loop, kept_state, hip_weights, config_test) into
zig/src/families/inkling2/hip_family.zig and pass one inkling2_family
module into the Inkling 2 HIP launcher and state modules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants